<?php
defined('IN_TS') or die('Access Denied.');

$planid = intval($_GET['id']);

//方案信息
$strPlan = $new['plan']->find('plan',array(
	'planid'=>$planid,
));

if($strPlan==''){
	header ( "HTTP/1.1 404 Not Found" );
	header ( "Status: 404 Not Found" );
	$title = '404';
	include pubTemplate ( "404" );
	exit ();
}


if($strPlan['isaudit']==1 && $TS_USER['isadmin']==0 || $strPlan['isaudit']==1 && $strPlan['userid']!=$TS_USER['userid'] && $TS_USER['isadmin']==0){
	tsNotice('方案审核中...');
}

$strPlan['title'] = tsTitle($strPlan['title']);
$strPlan['address'] = tsTitle($strPlan['address']);
$strPlan['content'] = tsDecode($strPlan['content']);
$strPlan['coordinate'] = tsTitle($strPlan['coordinate']);

$strPlan['user'] = aac('user')->getOneUser($strPlan['userid']);
$strPlan['group'] = aac('group')->getOneGroup($strPlan['groupid']);
$strPlan['type'] = $new['plan']->find('plan_type',array(
	
	'typeid'=>$strPlan['typeid'],

));

$cover =tsXimg($strPlan['photo'],'plan',500,'',$strPlan['path']);
// 是否点赞

$isRecommend = $new['plan']->findCount ( 'plan_recommend', array (
	'planid' => $planid,
	'userid' => $userid
) );


//plando
$isPlanUser = 0;
if($TS_USER['userid']){
	
	$userid = $TS_USER['userid'];
	
	$isPlanUser = $new['plan']->findCount('plan_users',array(
	
		'planid'=>$strPlan['planid'],
		'userid'=>$userid,
	
	));

	$isPlanGeter =  $new['plan']->findCount('plan_users',array(

		'planid'=>$strPlan['planid'],
		'userid'=>$userid,
		'status'=>1

	));


	if($isPlanUser){
		$strPlanUser = $new['plan']->find('plan_users',array(

			'planid'=>$strPlan['planid'],
			'userid'=>$userid,

		));
	}
	
}
$arrGroup = $new['plan']->findAll('group','isplace=2','groupid asc');

//申报这个方案的成员
$arrDoUsers = $new['plan']->findAll('plan_users',array(
	'planid'=>$strPlan['planid'],
),'addtime desc');

foreach($arrDoUsers as $key=>$item){
	$arrDoUser[] = $item;
	if(aac('user')->isUser($item['userid'])){
		$arrDoUser[$key]['user'] = aac('user')->getOneUser($item['userid']);
	}
}


//完成这个方案的人
$arrPlanUsers = $new['plan']->findAll('plan_users',array(
	'planid'=>$strPlan['planid'],
	'status'=>1,
),'addtime desc');

foreach($arrPlanUsers as $item){
	if(aac('user')->isUser($item['userid'])){
		$arrPlanUser[] = aac('user')->getOneUser($item['userid']);
	}
}


//评论

$page = isset($_GET['page']) ? intval($_GET['page']) : 1;

$url = tsUrl('plan','show',array('id'=>$planid,'page'=>''));

$lstart = $page*10-10;

$arrComments = $new['plan']->findAll('plan_comment',array(
	'planid'=>$strPlan['planid'],
),'addtime desc',null,$lstart.',10');

foreach($arrComments as $key=>$item){
	if(aac('user')->isUser($item['userid'])){
		$arrComment[$key] = $item;
		$arrComment[$key]['content'] = tsDecode($item['content']);
		$arrComment[$key]['user'] = aac('user')->getOneUser($item['userid']);
	}
}

$commentNum = $new['plan']->findCount('plan_comment',array(
	'planid'=>$strPlan['planid'],
));

$pageUrl = pagination($commentNum, 10, $page, $url);

$title = $strPlan['title'];
include template("show");